<?php defined('SYSPATH') or die('No direct access allowed.');

class Model_Fenxiao_Rank extends ORM {

    //获取当前等级名称
    public static function get_name($rankid)
    {
        $title = '';
        if($rankid==0)
        {
            $title = '暂无';
        }
        else
        {
            $title = DB::select('title')->from('fenxiao_rank')->where('id','=',$rankid)->execute()->get('title');
        }
        return $title;
    }

    //获取下一个等级信息
    public static function get_next_rank($memberid)
    {
        $sub_mids = Model_Fenxiao::get_sub_mids($memberid);
        $order_num = 0;
        if(!empty($sub_mids))
        {
            $order_num = DB::query(Database::SELECT, "select count(*) as num from sline_member_order where status=5 and memberid in (".implode(',',$sub_mids).")")->execute()->get('num');
        }
        $rank = DB::select()->from('fenxiao_rank')->where('min_order_num','>',$order_num)->order_by('id','asc')->execute()->current();
        if(empty($rank))
        {
            return null;
        }

        $rank['current_ordernum'] = $order_num;
        $rank['left_ordernum'] = $rank['min_order_num']-$order_num;
        return $rank;


    }
}